# @Timer:2022/3/28
# @作者:meng
# @文件名:正则表达式re.py
import re

a = r'hel\w+'
# b = re.compile(a)
# print(b.match('hello world'))

s1 = 'Hello8 worldsss'
s2 = 'world hello'
s3 = 'world Hello wolrd hello1'

'''match:从字符串开头匹配'''
# re1 = re.match(a,s1,flags=re.I)
# print(re1)
# re2 = re.match(a,s2,re.I)
# print(re2)
# re3 = re.match(a,s3,re.I)
# print(re3)
#
# print(re1.group())
# print(re1.span())
# print(re1.start())
# print(re1.end())

'''serch:从字符串中查找第一个匹配的对象'''
# re4 = re.search(a,s1,re.I)
# print(re4)
# re5 = re.search(a,s2,re.I)
# print(re5)
# re6 = re.search(a,s3,re.I)
# print(re6)

'''findall：在字符中中搜索所有符合条件的对象，并返回一个列表'''
# re7 = re.findall(a,s1,re.I)
# re8 = re.findall(a,s2,re.I)
# re9 = re.findall(a,s3,re.I)
# print(f"{re7}\n{re8}\n{re9}")

'''sub：字符串替换'''
# a = r'hel\w+'
# s1 = 'Hello8 worldsss'
# result1 = re.sub(a, '888', s1, flags=re.I)
# print(result1)

'''split'''
re1 = r'[#|&]'
url1 = "https://ke.qq.com/webcourse/index.html#cid=3172125&term_id=104501742&taid=12759712184428317&type=1024&vid=387702296412783537"
result2 = re.split(re1,url1)
print(result2)
